<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/7/6 0006
 * Time: 10:15
 */

namespace app\api\controller\v1\cleaner;


use app\api\controller\v1\Cleaner;
use think\Db;

class Info extends Cleaner
{
    public function index()
    {
        $this->success('success',$this->cleaner);
    }

    /**
     * 修改个人信息
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function save()
    {
        $data = $this->_input([
            'work_headimg' => $this->request->post('work_headimg'),
            'name' => $this->request->post('name'),
            'work_state' => $this->request->post('work_state'),
            'address' => $this->request->post('address'),
            'lat' => $this->request->post('lat'),
            'lng' => $this->request->post('lng')
        ],[
            'work_headimg' => 'url',
            'work_state' => 'in:0,1',
            'lat' => 'requireWith:address',
            'lng' => 'requireWith:address',
        ]);
        $work_data = [];
        if($data['work_state'] == '0')
        {
            $work_data = ['work_state' => '0'];
        }
        $data = array_filter($data);
        $data = array_merge($data,$work_data);
        empty($data) && $this->success('请选择要修改的内容！');
        $res = Db::name('Cleaner')->where('id','eq',$this->cid)->update($data);
        if($res !== false)
        {
            $this->success('修改成功！');
        } else {
            $this->error('修改失败！');
        }
    }
}